/*******************************************************************************
 * Copyright (c) 2009 Ordina and committers to Mod4j
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Ordina - initial implementation
 *******************************************************************************/
package org.mod4j.businessdomain.generator.helpers;

import java.util.List;

import com.ldh.mod4j.businessdomain.businessDomainDsl.BusinessClass;
import com.ldh.mod4j.businessdomain.businessDomainDsl.Property;
import com.ldh.mod4j.businessdomain.businessDomainDsl.UniqueRule;


public class BusinessRuleHelpers {

	/**
	 * Get unique rule of this property
	 * @param property: Property of class
	 * @return: Unique for property
	 */
	public static UniqueRule getUniqueRule(Property property){
		BusinessClass clazz = (BusinessClass) property.eContainer();
		List<UniqueRule> uniqueRules = BusinessClassHelpers.getUniqueRules(clazz);
		for (UniqueRule uniqueRule : uniqueRules) {
			if(uniqueRule.getProperties().contains(property)){
				return uniqueRule;
			}
		}
		return null;
	}
}
